﻿using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Blog.WebApi.Config
{
    public class AutofacModuleRegister : Autofac.Module
    {
        //注册接口和实现之间的关系
        protected override void Load(ContainerBuilder builder)
        {
            //利用反射进行注册
            Assembly interfaceAssembly = Assembly.Load("Blog.Interface");
            //foreach (var item in interfaceAssembly.GetTypes())
            //{
            //    Console.WriteLine(item.FullName);
            //}
            Assembly serviceAssembly = Assembly.Load("Blog.Service");
            builder.RegisterAssemblyTypes(interfaceAssembly, serviceAssembly)
                .AsImplementedInterfaces().InstancePerDependency();
            //InstancePerDependency()是瞬态周期，默认也是他
        }
    }
}
